<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>我的订单</title>
    <link rel="stylesheet" href="/style/weui.css"/>
    <link rel="stylesheet" href="/style/swiper.min.css"/>
    <link rel="stylesheet" href="/style/example.css"/>
    <link rel="stylesheet" href="/style/sweetalert.css"/>





</head>
<body ontouchstart>
<div class="page">
    <div class="page__bd" style="height: 100%;">
        <div class="weui-tab">
            <!-- header -->
            <div class="weui-navbar">
                <div class="weui-navbar__item <?=$status==0?'weui-bar__item_on':''?>" data-status="0">
                    <span>全部</span>
                </div>
                <?php if($shopType==1) { ?>
                <div class="weui-navbar__item <?=$status==100?'weui-bar__item_on':''?>" data-status="100">
                    <span>预订单</span>
                </div>
                <?php } ?>
                <div class="weui-navbar__item <?=$status==1?'weui-bar__item_on':''?>" data-status="1">
                    <span>待发货</span>
                </div>
                <div class="weui-navbar__item <?=$status==2?'weui-bar__item_on':''?>" data-status="2">
                    <span>待收货</span>
                </div>
                <div class="weui-navbar__item <?=$status==3?'weui-bar__item_on':''?>" data-status="3">
                    <span>已收货</span>
                </div>
                <div class="weui-navbar__item <?=$status==9?'weui-bar__item_on':''?>" data-status="9">
                    <span>作废</span>
                </div>
            </div>
            <!-- header end-->
            <div class="weui-tab__panel order-list" style="padding-bottom: 50px;">
                <!-- list -->
                <?php foreach ($list as $bill) {

                    if($status==100){
                        $orderNo = $bill['preBillNo'];
                    }else{
                        $orderNo = $bill['billNo'];
                    }

                    ?>


                    <div class="weui-panel weui-panel_access" id="order<?=$orderNo?>">
                        <?php
                            if($status == 100){
                                $link = "javascript:location.href='/order/pre-dtl?orderId={$bill['preBillNo']}'";
                            }else{
                                $link = "javascript:location.href='/order/dtl?billNo={$bill['billNo']}'";
                            }
                        ?>

                        <div class="weui-panel__bd" onclick="<?=$link?>">
                            <div class="weui-media-box weui-media-box_appmsg">
                                <div class="weui-media-box__bd">
                                    <h5 class="weui-media-box__title" style="float: left">
                                        <?php if($status==100) { ?>
                                            预订单号：<?=$bill['preBillNo']?>
                                        <?php } else { ?>
                                            订单编号：<?=$bill['billNo']?>
                                        <?php } ?>

                                    </h5>
                                    <h5 class="weui-media-box__title" style="float: right">

                                        <?php if($status==100) { ?>
                                            金额：<?=$bill['payPrice']?> 元
                                        <?php } else { ?>
                                            数量：<?=$bill['totalQty']?>
                                        <?php } ?>

                                    </h5>
                                    <div style="clear: both"></div>
                                    <p style="float: left">门店：<?=$bill['ShopName']?></p>
                                    <p style="float: right">创建人：<?=$bill['creator']?></p>
                                </div>
                            </div>
                        </div>
                        <div class="weui-panel__ft">
                            <div class="weui-cell weui-cell_access weui-cell_link">
                                <div class="weui-cell__bd"><?=date('Y-m-d',strtotime($bill['createTime'])) ?></div>
                                <div class="weui-cell__ft">
                                    <?php if($status==100) { ?>
                                        <span class="text-gray"><?=$bill['statusName']?></span>

                                        <?php if($bill['billStatus']==1) {?>
                                            <a href="javascript:OrderHandler.cancelPay('<?=$bill['preBillNo']?>');" class="weui-btn weui-btn_mini weui-btn_warn">取消</a>
                                            <a href="javascript:pay('<?=$bill['preBillNo']?>');" class="weui-btn weui-btn_mini weui-btn_warn">去支付</a>
                                        <?php } ?>

                                    <?php } else { ?>
                                        <?php if($bill['billStatus'] == 0 || $bill['billStatus'] == 1) { ?>
                                            <span class="text-gray">待发货</span>
                                        <?php } elseif($bill['billStatus'] == 2) { ?>
                                            <span class="text-red">待收货</span>
                                        <?php } elseif($bill['billStatus'] == 3) { ?>
                                            <span class="text-green">已收货</span>
                                        <?php } elseif($bill['billStatus'] == 9) { ?>
                                            <span class="text-gray">已作废</span>
                                        <?php } ?>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php } ?>
                <!-- list end-->
            </div>
            <div class="weui-tabbar">
                <a href="/" class="weui-tabbar__item">
                    <span class="weui-tabbar__icon"><i class="icon iconfont icon-home"></i></span>
                    <p class="weui-tabbar__label">首页</p>
                </a>
                <a href="/product" class="weui-tabbar__item">
                    <span class="weui-tabbar__icon"><i class="icon iconfont icon-commodity"></i></span>
                    <p class="weui-tabbar__label">商品</p>
                </a>
                <a href="/cart" class="weui-tabbar__item">
                    <span class="weui-tabbar__icon"><i class="icon iconfont icon-buy"></i></span>
                    <p class="weui-tabbar__label">购物车</p>
                </a>
                <a href="/order/list" class="weui-tabbar__item weui-bar__item_on">
                    <span class="weui-tabbar__icon"><i class="icon iconfont icon-my"></i></span>
                    <p class="weui-tabbar__label">我的订单</p>
                </a>
            </div>
        </div>
    </div>
</div>

<script src="/js/zepto.min.js"></script>
<script src="/js/sweetalert.min.js"></script>
<script src="/js/swiper.min.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>


<script>

     OrderHandler = {
         cancelPay: function (preBillNo) {

             swal({
                 title: '取消订单?',
                 confirmButtonText: "是",
                 cancelButtonText: "否",
                 showCancelButton: true,
                 closeOnConfirm: true
             }, function (flg) {
                 if(flg){
                     $.post('/order/cancel-pre', {'preBillNo': preBillNo}, function (o) {
                         console.log(o);
                         if (o.code == 200) {
                             swal('取消成功');
                             $("#order"+preBillNo).remove();

                         } else {
                             swal(o.msg);
                         }
                     },'json')
                 }
                 // swal.close();
             });

         },

     };



     function pay(billNo) {
         submit_pre(billNo);
     }

     function submit_pre(billNo) {
         swal('订单提交中...');
         var url = '/order/submit-pre-re';
         $.post(url, {'preBillNo': billNo}, function (o) {

             if (o.code == 200) {
                 console.log(o.data.url);
                 location.href = o.data.url;
             } else {
                 swal(o.msg);
                 if (o.code == 501) {
                     setTimeout(function () {
                         location.href = '/cart';
                     }, 1500);
                 }
             }
         },'json')
     }


    $(function() {

        // var $loadingToast = $('#loadingToast');
        // $('.weui-uploader__input-box').on('click', function(){
        //     if ($loadingToast.css('display') != 'none') return;
        //     $loadingToast.fadeIn(100);
        //     setTimeout(function () {
        //         $loadingToast.fadeOut(100);
        //     }, 1000);
        // });


        $('.weui-navbar__item').on('click', function () {
            $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
            var status = $(this).attr('data-status');
            location.href = '/order/list?status=' + status;
        });





    });



</script>
</body>
</html>
